package com.zxtc.wh.servlet;

import com.opensymphony.xwork2.ActionSupport;
import com.zxtc.wh.utils.FileUploadSaveUtil;
import org.apache.struts2.ServletActionContext;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

//@WebServlet("/downloadFile")
public class DownloadFile extends ActionSupport   /*HttpServlet*/ {


    String filePath;
    InputStream inputStream;

    public InputStream getInputStream() {
        return inputStream;
    }

    public void setInputStream(InputStream inputStream) {
        this.inputStream = inputStream;
    }

    public String getFilePath() {
        return filePath;
    }

    public void setFilePath(String filePath) {
        this.filePath = filePath;
    }


    //    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//
////        String queryString = req.getQueryString();
//        String filePath = req.getParameter("filePath");
////        resp.addHeader("content-disposition", "attachment;filename=" + filePath);
//
//        File file = FileUploadSaveUtil.getResourceFile(this, filePath);
//        IOUtils.copy(new FileInputStream(file), resp.getOutputStream());
//    }

    @Override
    public String execute() throws Exception {


        File file = FileUploadSaveUtil.getResourceFile(ServletActionContext.getServletContext(), filePath);
        inputStream = new FileInputStream(file);

        System.out.println(this.getClass().toGenericString());
        return "input";


    }


}
